home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bplus20.zip / VTEST.C < prev   
Text File  |  1989-02-13  |  3KB  |  104 lines

  1. /*                     VTEST.C test program.                        */
  2. /*  This is a simple test program which creates two index files.    */
  3. /*  100 keys are added to each file, some keys are deleted and      */
  4. /*  then the keys are added back to the file.  The keys are listed  */
  5. /*  in ascending and decending order.                               */
  6.  
  7. #include "bplus.h"
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <conio.h>
  11.  
  12. /* extern bplus_network;  */
  13.  
  14. IX_DESC name1, name2;        /* index file variables */
  15.  
  16. void uplist(name)            /* list keys in ascending order */
  17.   IX_DESC *name;
  18.   {
  19.     ENTRY ee;
  20.     first_key(name);
  21.     while (next_key(&ee, name) == IX_OK) printf("%s   ",ee.key);
  22.     printf("\nPress any key to continue \n");
  23.     getch();
  24.   }
  25.  
  26. void downlist(name)           /* list keys in decending order  */
  27.   IX_DESC *name;
  28.   {
  29.     ENTRY ee;
  30.     last_key(name);
  31.     while (prev_key(&ee, name) == IX_OK) printf("%s   ",ee.key);
  32.     printf("\nPress any key to continue \n");
  33.     getch();
  34.   }
  35.  
  36. main()
  37.   {
  38.     int i;
  39.     clock_t clock(void);
  40.     float stime, etime;
  41.     ENTRY e;
  42. /*  bplus_network = 0;      */
  43.     printf("Make two index files\n");
  44.     make_index("test1.idx",&name1, 0);
  45.     make_index("test2.idx",&name2, 1);
  46.     printf("Indexing 100 items in two index files:\n");
  47.  
  48.     /* note the time to index */
  49.     stime = clock();
  50.     /* add 100 keys to each index file */
  51.     for (i = 0; i < 100; i++)
  52.       {
  53.     e.recptr = (long) i;
  54.         sprintf(e.key, "VALUE1-%2d",i);
  55.         add_key(&e, &name1);
  56.         sprintf(e.key, "VALUE2-%2d",i);
  57.         add_key(&e, &name2);
  58.       }
  59.  
  60.     /* print the time required for indexing the two files */
  61.     etime = clock();
  62.     printf("Indexing is complete.  The time was %f\n\n", (etime - stime)/CLK_TCK);
  63.     printf("List the keys in each index file in ascending order:\n\n");
  64.     uplist(&name1);
  65.     uplist(&name2);
  66.  
  67.     /* delete some keys and list again */
  68.     printf("\nNow delete all keys from 20 to 90 in each file\n\n");
  69.     for (i = 20; i < 90; i++)
  70.       {
  71.     e.recptr = (long) i;
  72.         sprintf(e.key, "VALUE1-%2d",i);
  73.         delete_key(&e, &name1);
  74.         sprintf(e.key, "VALUE2-%2d",i);
  75.         delete_key(&e, &name2);
  76.       }
  77.     printf("List the keys now for each index file in ascending order:\n\n");
  78.     uplist(&name1);
  79.     uplist(&name2);
  80.  
  81.     /* add the keys back and list again */
  82.     printf("Now add back all items from 20 to 90 to each index\n\n");
  83.     for (i = 20; i < 90; i++)
  84.       {
  85.     e.recptr = (long) i;
  86.         sprintf(e.key, "VALUE1-%d",i);
  87.         add_key(&e, &name1);
  88.         sprintf(e.key, "VALUE2-%d",i);
  89.         add_key(&e, &name2);
  90.       }
  91.     printf("List the keys for each index file again in ascending order:\n\n");
  92.     uplist(&name1);
  93.     uplist(&name2);
  94.  
  95.     /* list both files in decending order */
  96.     printf("List the keys for each index file in decending order\n\n");
  97.     downlist(&name1);
  98.     downlist(&name2);
  99.  
  100.     /* always close all files */
  101.     close_index(&name1);
  102.     close_index(&name2);
  103.   }
  104.